﻿Public Class language

    Public Class sign_r
        Public lang As String
        Public sign As String
        Public ext As String
        Public trash As String

        Sub New(ByVal l As String, ByVal s As String, ByVal e As String, ByVal t As String)
            lang = l
            sign = s
            ext = e
            trash = t
        End Sub
    End Class

    Public Class sign

        Private signs(0 To 4) As String
        Private langs(0 To 4) As String
        Private ext(0 To 4) As String
        Private trash(0 To 4) As String

        Public Sub New()

            signs(0) = "*.vb"
            signs(1) = "*.c"
            signs(2) = "*.cpp"
            signs(3) = "*.html"
            signs(4) = "*.php"

            langs(0) = "Visual basic"
            langs(1) = "C"
            langs(2) = "CPP"
            langs(3) = "HTML"
            langs(4) = "PHP"

            ext(0) = ".vb"
            ext(1) = ".c"
            ext(2) = ".cpp"
            ext(3) = ".html"
            ext(4) = ".php"

            trash(0) = "%appdata%\omnisource\VB.trash"
            trash(1) = "%appdata%\omnisource\CPP.trash"
            trash(2) = "%appdata%\omnisource\C.trash"
            trash(3) = "%appdata%\omnisource\default.trash"
            trash(4) = "%appdata%\omnisource\default.trash"

        End Sub

        Public Function getsign(ByVal index As Integer) As String
            Return signs(index)
        End Function

        Public Function get_lan(ByVal index As Integer) As String
            Return langs(index)
        End Function

        Public Function get_ext(ByVal index As Integer) As String
            Return ext(index)
        End Function

        Public Function get_trash(ByVal index As Integer) As String
            Return trash(index)
        End Function
    End Class

    Private Function present(ByVal signature As String, ByVal ext As String, ByVal path As String) As Boolean
        Dim b As Boolean
        For Each FoundFile As String In FileIO.FileSystem.GetFiles(path, FileIO.SearchOption.SearchAllSubDirectories, signature)
            If FoundFile.Contains(ext) Then
                b = True
                Exit For
            Else
                b = False
            End If
        Next
        Return b
    End Function

    Public Function get_lan(ByVal path As String) As String
        Dim s As New sign
        Dim lan As String
        lan = "Default"
        For index = 0 To 4
            If present(s.getsign(index), s.get_ext(index), path) Then
                lan = s.get_lan(index)
                Exit For
            Else
                lan = "Default"
            End If
        Next
        Return lan
    End Function

End Class
